<template>
  <div id="activeTopSearch">
    <div class="search-box">
      <el-form
        ref="ruleForm"
        :inline="true"
        :model="formInline"
        :rules="rules"
        class="demo-form-inline"
      >
        <el-form-item label="搜索：" prop="activityId">
          <el-input
            v-model="formInline.name"
            placeholder="请输入活动名称"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="状态：" prop="status">
          <el-select v-model="formInline.state" clearable placeholder="请选择">
            <el-option
              v-for="item in statusOptions"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="学院：" prop="">
          <el-select
            v-model="formInline.collegeId"
            clearable
            placeholder="请选择"
          >
            <el-option
              v-for="item in collegeList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="活动分类：" prop="status">
          <el-select
            v-model="formInline.specificActivityType"
            clearable
            placeholder="请选择"
          >
            <el-option
              v-for="item in activesOptions"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="时间：">
          <el-date-picker
            style="width:400px"
            v-model="formInline.time"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="yyyy-MM-dd HH:mm:ss"
            format="yyyy-MM-dd HH:mm:ss"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item class="s-btn">
          <el-button type="success" icon="el-icon-search" @click="toSearch()">
            查询
          </el-button>
          <el-button type="success" plain @click="reset">
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { sysNormalDisable } from '@utils/dictionariesFunc'

export default {
  watch: {
    'formInline.time': {
      immediate: true,
      handler(newV, oldV) {
        if (newV == null) {
          this.formInline.createdTimeStart = ''
          this.formInline.createdTimeEnd = ''
        } else {
          this.formInline.createdTimeStart = newV[0]
          this.formInline.createdTimeEnd = newV[1]
        }
      },
      deep: true
    }
  },
  props: {
    formInline: {
      type: Object,
      default: function() {
        return {
          time: [],
          name: '',
          collegeId: '',
          createdTimeStart: '',
          createdTimeEnd: '',
          specificActivityType: '',
          state: ''
        }
      }
    }
  },
  data() {
    return {
      time: [],
      checkCollege: '',
      collegeList: [],
      statusOptions: [],
      activesOptions: [],
      activesValue: '',
      statusValue: '',
      userType: [],
      rules: {
        activityId: {},
        type: {},
        createTime: ''
      }
      // pickerTopDataDay: {
      //   disabledDate(time) {
      //     //昨天之后不可选
      //     const yesterday = new Date() - 3600 * 1000 * 24 * 1
      //     return time.getTime() < yesterday
      //   }
      // }
    }
  },
  mounted() {
    this.getColleges()
    this.getActivesTypes()
    this.getActivesStates()
  },
  methods: {
    async getActivesStates() {
      let data = await sysNormalDisable(
        'marketing_activity_state',
        'marketing_activity_state'
      )
      let addAll = [{ dictLabel: '全部', dictValue: '' }]
      this.statusOptions = addAll.concat(data)
    },
    async getActivesTypes() {
      let data = await sysNormalDisable(
        'specific_marketing_activity_type',
        'specific_marketing_activity_type'
      )
      let slectData = data.filter((item) => {
        return item.dictValue !== 'INVITE_ACTIVITY'
      })
      let addAll = [{ dictLabel: '全部', dictValue: '' }]
      this.activesOptions = addAll.concat(slectData)
    },
    async getColleges() {
      let data = await sysNormalDisable('sys_college', 'sys_college')
      let addAll = [{ dictLabel: '全部', dictValue: '' }]
      this.collegeList = addAll.concat(data)
    },
    toSearch(formName) {
      this.$emit('toSearch')
    },
    /* 重置 */
    reset() {
      this.$refs['ruleForm'].resetFields()
      this.setDefaultValue()
    },
    setDefaultValue() {
      this.formInline.name = ''
      this.formInline.time = ''
      this.formInline.collegeId = ''
      this.formInline.createdTimeStart = ''
      this.formInline.createdTimeEnd = ''
      this.formInline.specificActivityType = ''
      this.formInline.state = ''
    }
  }
}
</script>

<style lang="less" scoped>
.search-box :deep(.el-input__inner) {
  padding: 0 30px;
}
</style>
